package com.jxw.launcher.view;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.View;
import com.jxw.launcher.R;

/* loaded from: classes.dex */
public class JxwBattery extends View {
    private ValueAnimator animator;
    private int chargingQuantity;
    private int colorBCBCBE;
    private String colorBCBCBEx;
    private int colorE21E1E;
    private int height;
    private boolean isCharging;
    private float mBatteryHeadHeight;
    private float mBatteryHeadMargin;
    private RectF mBatteryHeadRectF;
    private float mBatteryHeadWidth;
    private Paint mChargingBitmapPaint;
    private float mMargin;
    private float mMiddleWidth;
    private Paint mOuterPaint;
    private RectF mOuterRectF;
    private float mOuterRound;
    private float mOuterStrokeWidth;
    private Paint mProgressPaint;
    private float mUnitStrokeWidth;
    private int quantity;
    private int width;

    private void initBitmap() {
    }

    private void onChargingDraw(Canvas canvas) {
    }

    public JxwBattery(Context context) {
        this(context, null);
    }

    public JxwBattery(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public JxwBattery(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.colorBCBCBE = Color.parseColor("#FFFFFF");
        this.colorBCBCBEx = "#FFFFFF";
        this.colorE21E1E = Color.parseColor("#FFFFFF");
        this.quantity = 29;
        initParameter();
        initAllPaints();
        initBitmap();
        initAnimator();
    }

    private void initAnimator() {
        this.animator = ValueAnimator.ofInt(0, 100);
        this.animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.jxw.launcher.view.JxwBattery.1
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                JxwBattery.this.chargingQuantity = ((Integer) valueAnimator.getAnimatedValue()).intValue();
                JxwBattery.this.invalidateView();
            }
        });
        this.animator.setRepeatCount(-1);
        this.animator.setDuration(3000L);
        this.animator.start();
    }

    public void setColor(int i) {
        this.colorBCBCBE = i;
        initAllPaints();
        invalidate();
    }

    public void setColorx(String str) {
        this.colorBCBCBEx = str;
        initAllPaints();
        invalidate();
    }

    public void setColor(int i, int i2) {
        this.colorBCBCBE = i;
        this.colorE21E1E = i2;
        initAllPaints();
        invalidate();
    }

    private void initParameter() {
        this.mUnitStrokeWidth = getResources().getDimension(R.dimen.x1);
        this.mOuterStrokeWidth = getResources().getDimension(R.dimen.x1);
        this.mBatteryHeadWidth = getResources().getDimension(R.dimen.x1);
        this.mBatteryHeadHeight = getResources().getDimension(R.dimen.x1);
        this.mBatteryHeadMargin = getResources().getDimension(R.dimen.x1);
        this.mOuterRound = getResources().getDimension(R.dimen.x1);
        this.mMargin = getResources().getDimension(R.dimen.x2);
        this.mMiddleWidth = getResources().getDimension(R.dimen.x2);
    }

    private void initAllPaints() {
        this.mOuterPaint = new Paint();
        this.mOuterPaint.setDither(true);
        this.mOuterPaint.setAntiAlias(true);
        this.mOuterPaint.setColor(this.colorBCBCBE);
        this.mProgressPaint = new Paint();
        this.mProgressPaint.setDither(true);
        this.mProgressPaint.setAntiAlias(true);
        this.mProgressPaint.setColor(this.colorBCBCBE);
        this.mProgressPaint.setStrokeWidth(this.mUnitStrokeWidth);
        this.mProgressPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        this.mChargingBitmapPaint = new Paint();
        this.mChargingBitmapPaint.setDither(true);
        this.mChargingBitmapPaint.setAntiAlias(true);
        this.mChargingBitmapPaint.setFilterBitmap(true);
    }

    @Override // android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        this.width = getMeasuredWidth();
        this.height = getMeasuredHeight();
        float f = this.mMargin;
        this.mOuterRectF = new RectF(f, f, ((this.width - f) - this.mBatteryHeadWidth) - this.mBatteryHeadMargin, this.height - f);
        int i3 = this.width;
        float f2 = i3 - this.mBatteryHeadWidth;
        int i4 = this.height;
        float f3 = this.mBatteryHeadHeight;
        this.mBatteryHeadRectF = new RectF(f2, (i4 / 2) - f3, i3, (i4 / 2) + f3);
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        onOuterDraw(canvas);
        onProgressDraw(canvas);
        if (this.isCharging) {
            onChargingDraw(canvas);
        }
    }

    private void onOuterDraw(Canvas canvas) {
        this.mOuterPaint.setStrokeWidth(this.mOuterStrokeWidth);
        this.mOuterPaint.setStyle(Paint.Style.STROKE);
        RectF rectF = this.mOuterRectF;
        float f = this.mOuterRound;
        canvas.drawRoundRect(rectF, f, f, this.mOuterPaint);
        this.mOuterPaint.setStrokeWidth(this.mUnitStrokeWidth);
        this.mOuterPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawRect(this.mBatteryHeadRectF, this.mOuterPaint);
    }

    private void onProgressDraw(Canvas canvas) {
        if (!this.isCharging) {
            if (this.quantity > 15) {
                this.mProgressPaint.setColor(this.colorBCBCBE);
            } else {
                this.mProgressPaint.setColor(this.colorE21E1E);
            }
        } else {
            this.mProgressPaint.setColor(this.colorBCBCBE);
        }
        float f = ((this.width - (this.mMargin * 2.0f)) - (this.mMiddleWidth * 2.0f)) - (this.mOuterStrokeWidth * 4.0f);
        int i = this.isCharging ? this.chargingQuantity : this.quantity;
        float f2 = this.mMargin;
        float f3 = this.mOuterStrokeWidth;
        float f4 = this.mMiddleWidth;
        canvas.drawRect(new RectF(f2 + f3 + f4, f2 + f3 + f4, f2 + f3 + f4 + (f * (i / 100.0f)), ((this.height - f2) - f3) - f4), this.mProgressPaint);
    }

    public void setPower(int i, boolean z) {
        this.quantity = i;
        this.isCharging = z;
        checkQuantity();
        if (this.isCharging && this.quantity < 100) {
            if (this.animator.isRunning() || this.animator.isStarted()) {
                return;
            }
            this.animator.start();
            return;
        }
        if (this.animator.isStarted() || this.animator.isRunning()) {
            this.animator.cancel();
        }
        this.isCharging = false;
        invalidateView();
    }

    private void checkQuantity() {
        int i = this.quantity;
        if (i < 0) {
            this.quantity = 0;
        } else if (i > 100) {
            this.quantity = 100;
        }
    }

    @Override // android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void invalidateView() {
        if (Looper.getMainLooper() == Looper.myLooper()) {
            invalidate();
        } else {
            postInvalidate();
        }
    }
}
